
<template>
  <!-- 客户信息 -->
  <div class="kehuxinxi">
    <div class="search">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="输入搜索">
          <el-input v-model="formInline.key" placeholder="请输入企业名称"></el-input>
        </el-form-item>
        <el-form-item label="输入时间">
          <el-date-picker
            v-model="formInline.time1"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            @change="chage"
          ></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onsubmit">查询</el-button>
        </el-form-item>
        <!-- <el-form-item>
          <el-button type="text">清空筛选条件</el-button>
        </el-form-item>-->
      </el-form>
    </div>
    <el-table class="table" stripe :data="tableData" style="width: 100%" height="580">
      <el-table-column prop="xuhao" label="序号" align="center"></el-table-column>
      <el-table-column prop="componyno" label="客户编号" align="center"></el-table-column>
      <el-table-column prop="componyname" label="企业名称" align="center" show-overflow-tooltip></el-table-column>
      <el-table-column prop="linkman" label="联系人" align="center"></el-table-column>
      <el-table-column prop="linkphone" label="联系方式" align="center"></el-table-column>
      <el-table-column prop="time" label="录入时长" align="center"></el-table-column>
      <el-table-column prop="state" label="状态" align="center"></el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button size="small" type="primary" @click="xiangqing(scope.row.componyno)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="pgnt">
      <el-pagination
        background
        layout="prev, pager, next"
        :current-page="current"
        :page-size="pagesize"
        @current-change="handleCurrentChange"
        :total="total"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      formInline: {
        key: ""
      },
      tableData: [],
      total: 1,
      current: 1,
      pagesize: 10,
      start: "",
      end: ""
    };
  },
  created() {
    this.getData(0);
    this.getDatas();
  },
  methods: {
    getData(page) {
      var obj = {
        start: this.start,
        end: this.end,
        key: this.formInline.key,
        pn: page,
        PerPageSize: 10
      };
      var objs = JSON.stringify(obj);
      axios(
        "/apis/PresidentManagement.asmx/Customerinfo?index=1&jsondata=" + objs
      ).then(({ data }) => {
        var datas = this.$x2js.xml2js(data);
        var list = JSON.parse(datas.string.__text);
        console.log(list);
        for(var i = 0;i < list.length;i++) {
          list[i].xuhao = i + 1 + page*10
        }
        this.tableData = [];
        this.tableData = list;
      });
    },
    getDatas() {
      var obj = {
        start: "",
        end: "",
        key: this.formInline.key,
        pn: 0,
        PerPageSize: 10000
      };
      var objs = JSON.stringify(obj);
      axios(
        "/apis/PresidentManagement.asmx/Customerinfo?index=1&jsondata=" + objs
      ).then(({ data }) => {
        var datas = this.$x2js.xml2js(data);
        var list = JSON.parse(datas.string.__text);
        console.log(list);
        this.total = list.length;
      });
    },
    xiangqing(e) {
      this.$router.push({ path: "./KehuDetails", query: { no: e } });
    },
    // 分页
    handleCurrentChange(e) {
      this.getData(e - 1);
    },
    // 日期改变
    chage(e) {
      console.log(e);
      if (e) {
        this.start = e[0];
        this.end = e[1];
      }else{
        this.start = ""
        this.end = ""
      }
    },
    // 筛选
    onsubmit() {
      this.getData(0);
    }
  }
};
</script>

<style lang="scss" scoped>
.kehuxinxi {
  padding-left: 10px;
  padding-right: 10px;
  padding-top: 10px;
}
.search {
  height: 50px;
  border-radius: 5px;
  background-color: #fff;
  padding-left: 20px;
  padding-top: 10px;
  margin-bottom: 20px;
}
.table {
  margin-bottom: 20px;
  padding-left: 20px;
}
.pgnt {
  text-align: center;
}
.demo-form-inline {
  display: inline-block;
}
.ebtn {
  float: right;
  margin-right: 20px;
}
</style>